<!--

    Copyright © 2016-2025 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<section style="padding-bottom: 16px; margin: 0">
  <mat-tab-group dynamicHeight>
    <mat-tab label="{{ 'device-profile.lwm2m.model-tab' | translate }}">
      <ng-template matTabContent>
        <section [formGroup]="lwm2mDeviceProfileFormGroup">
          <tb-profile-lwm2m-object-list
            (addList)="addObjectsList($event)"
            (removeList)="removeObjectsList($event)"
            formControlName="objectIds">
          </tb-profile-lwm2m-object-list>
          <mat-checkbox formControlName="initAttrTelAsObsStrategy">
              <span tb-hint-tooltip-icon="{{ 'device-profile.lwm2m.init-attr-tel-as-obs-strategy-hint' | translate }}">
                {{ 'device-profile.lwm2m.init-attr-tel-as-obs-strategy' | translate }}
              </span>
          </mat-checkbox>
          <mat-form-field class="mat-block">
            <mat-label translate>device-profile.lwm2m.observe-strategy.observe-strategy</mat-label>
            <mat-select formControlName="observeStrategy">
              <mat-select-trigger>
                {{ observeStrategyMap.get(lwm2mDeviceProfileFormGroup.get('observeStrategy').value)?.name | translate }}
              </mat-select-trigger>
              <mat-option *ngFor="let strategy of observeStrategyList" [value]="strategy">
                {{ observeStrategyMap.get(strategy).name | translate  }}
                <small style="display: block;">
                  {{ observeStrategyMap.get(strategy).description | translate }}
                </small>
              </mat-option>
            </mat-select>
          </mat-form-field>
          <tb-profile-lwm2m-observe-attr-telemetry
            formControlName="observeAttrTelemetry">
          </tb-profile-lwm2m-observe-attr-telemetry>
        </section>
      </ng-template>
    </mat-tab>
    <mat-tab label="{{ 'device-profile.lwm2m.bootstrap-tab' | translate }}">
      <section [formGroup]="lwm2mDeviceProfileFormGroup">
        <div *ngIf="!isTransportWasRunWithBootstrap" style="padding:16px 0 0 8px;" class="flex flex-row items-end justify-start">
          <mat-icon color="warn" class="material-icons" style="margin-right:8px;">warning</mat-icon>
          <span style="font-weight:500">LwM2M transport was run without bootstrap server</span>
        </div>
        <mat-checkbox formControlName="bootstrapServerUpdateEnable" style="margin-left:8px;margin-top:20px">
          {{ 'device-profile.lwm2m.include-bootstrap-server' | translate }}
        </mat-checkbox>
        <section style="padding: 20px 2px">
          <tb-profile-lwm2m-bootstrap-config-servers formControlName="bootstrap"
                                                     [isBootstrapServerUpdateEnable]="isBootstrapServerUpdateEnable"
                                                     [(isTransportWasRunWithBootstrap)]="isTransportWasRunWithBootstrap">
          </tb-profile-lwm2m-bootstrap-config-servers>
        </section>
      </section>
    </mat-tab>
    <mat-tab label="{{ 'device-profile.lwm2m.others-tab' | translate }}">
      <ng-template matTabContent [formGroup]="lwm2mDeviceProfileFormGroup">
        <section formGroupName="clientLwM2mSettings">
          <fieldset class="fields-group">
            <legend class="group-title" translate>device-profile.lwm2m.ota-update</legend>
            <mat-checkbox formControlName="useObject19ForOtaInfo">
              <span tb-hint-tooltip-icon="{{ 'device-profile.lwm2m.use-object-19-for-ota-update-hint' | translate }}">
                {{ 'device-profile.lwm2m.use-object-19-for-ota-update' | translate }}
              </span>
            </mat-checkbox>
            <fieldset class="fields-group">
              <legend class="group-title" translate>device-profile.lwm2m.fw-update</legend>
              <mat-form-field class="mat-block flex-1">
                <mat-label>{{ 'device-profile.lwm2m.fw-update-strategy' | translate }}</mat-label>
                <mat-select formControlName="fwUpdateStrategy">
                  <mat-option [value]=1>{{ 'device-profile.lwm2m.fw-update-strategy-package' | translate }}</mat-option>
                  <mat-option [value]=2>{{ 'device-profile.lwm2m.fw-update-strategy-package-uri' | translate }}</mat-option>
                  <mat-option [value]=3>{{ 'device-profile.lwm2m.fw-update-strategy-data' | translate }}</mat-option>
                </mat-select>
              </mat-form-field>
              <mat-form-field class="mat-block flex-1" *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateStrategy').value === 2">
                <mat-label>{{ 'device-profile.lwm2m.fw-update-resource' | translate }}</mat-label>
                <input matInput formControlName="fwUpdateResource" required>
                <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').hasError('required')">
                  {{ 'device-profile.lwm2m.fw-update-resource-required' | translate }}
                </mat-error>
              </mat-form-field>
            </fieldset>
            <fieldset class="fields-group">
              <legend class="group-title" translate>device-profile.lwm2m.sw-update</legend>
              <mat-form-field class="mat-block flex-1">
                <mat-label>{{ 'device-profile.lwm2m.sw-update-strategy' | translate }}</mat-label>
                <mat-select formControlName="swUpdateStrategy">
                  <mat-option [value]=1>{{ 'device-profile.lwm2m.sw-update-strategy-package' | translate }}</mat-option>
                  <mat-option [value]=2>{{ 'device-profile.lwm2m.sw-update-strategy-package-uri' | translate }}</mat-option>
                </mat-select>
              </mat-form-field>
              <mat-form-field class="mat-block flex-1" *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateStrategy').value === 2">
                <mat-label>{{ 'device-profile.lwm2m.sw-update-resource' | translate }}</mat-label>
                <input matInput formControlName="swUpdateResource" required>
                <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').hasError('required')">
                  {{ 'device-profile.lwm2m.sw-update-resource-required' | translate }}
                </mat-error>
              </mat-form-field>
            </fieldset>
          </fieldset>
          <fieldset class="fields-group">
            <legend class="group-title" translate>device-profile.power-saving-mode</legend>
            <tb-power-mode-settings [parentForm]="clientSettingsFormGroup">
            </tb-power-mode-settings>
          </fieldset>
          <fieldset class="fields-group">
            <legend class="group-title" translate>device-profile.lwm2m.default-object-id</legend>
            <mat-form-field class="flex-1">
              <mat-select formControlName="defaultObjectIDVer">
                <mat-option *ngFor="let objectIDVer of objectIDVers" [value]="objectIDVer">
                  {{ objectIDVerTranslationMap.get(objectIDVer) | translate }}
                </mat-option>
              </mat-select>
            </mat-form-field>
          </fieldset>
        </section>
      </ng-template>
    </mat-tab>
    <mat-tab label="{{ 'device-profile.lwm2m.config-json-tab' | translate }}">
      <ng-template matTabContent>
        <section style="padding: 8px 0">
          <tb-json-object-edit
            readonly
            [sort]="sortFunction"
            label="{{ 'device-profile.transport-type-lwm2m' | translate }}"
            [ngModel]="configurationValue">
          </tb-json-object-edit>
        </section>
      </ng-template>
    </mat-tab>
  </mat-tab-group>
</section>
